import interpreter.ShapeBase;

import javax.swing.*;
import javax.swing.border.Border;

import GUI.ButtonsPanel;


import observer.ObserverClassic;

import composite.DocumentManager;

import java.awt.BorderLayout;
import java.awt.Container;

/** Main entry point of the simple draw application  **/
@SuppressWarnings("serial")
public class SimpleDraw extends JApplet
{
	public static JTextField textField;
	/** Place for the instance of singleton */
	ShapeBase shapeBase;
	
	public void init() {		
		//Create the instance of ShapeBase - database of shapes, parsed from the xml
		try {
			shapeBase = ShapeBase.getInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		// Create the new document
		DocumentManager docuMan = new DocumentManager(); // it is observed by the observers
		addMouseListener(docuMan.new DrawingPanelMouseListener());
		addMouseMotionListener(docuMan.new MyMouseMotionListener());
		
		// Add observers
		ObserverClassic observerClassic = new ObserverClassic();
		// This observer draws the image on the panel, when document state changes
		docuMan.addObserver(observerClassic);
		  
		// Second observer, not implemented yet
		//ObserverSecond observerSecond = new ObserverSecond(g);
		//docuMan.addObserver(observerSecond);
		
		// Refresh the document, observers will notice it
		docuMan.refreshRoot();
		
		/** GUI **/
		
		//Get the main applet window
		Container content_pane = getContentPane();
		
		//Create the drawing place
		JPanel drawing_panel = observerClassic.getDrawing_panel();
		Border border2 = BorderFactory.createTitledBorder("Drawing area");
		drawing_panel.setBorder(border2);
		
		// Panel to group all the button panel
		ButtonsPanel buttons_panel = new ButtonsPanel(shapeBase, docuMan);

		// Add panels to the contentPane
		//Drawing
		content_pane.add(drawing_panel,BorderLayout.CENTER);
		//Buttons
		content_pane.add(buttons_panel,BorderLayout.SOUTH);
	}
  
} // class DrawApplet